﻿@using Volo.Abp.UI.Navigation
@model ApplicationMenuItem
@{
    var elementId = string.IsNullOrEmpty(Model.ElementId) ? string.Empty : $"id=\"{Model.ElementId}\"";
    var cssClass = string.IsNullOrEmpty(Model.CssClass) ? string.Empty : Model.CssClass;
    var disabled = Model.IsDisabled ? "disabled" : string.Empty;
    var icon = string.IsNullOrEmpty(Model.Icon) ? string.Empty : Model.Icon;
    var collapsePages = string.IsNullOrEmpty(Model.ElementId) ? Model.GetHashCode().ToString() : Model.ElementId;
    collapsePages = $"collapsePages-{collapsePages}";


    var isActive = this.Context.Request.Path == Model.Url || Model.Items.Any(a => a.Url == this.Context.Request.Path) ? true : false;
}

<li class="nav-item @(isActive?" active":"") ">
    @if (Model.IsLeaf)
    {
        if (Model.Url != null)
        {
            <a class="nav-link @cssClass @disabled" href="@(Model.Url ?? " #")" @Html.Raw(elementId)>
                <i class="@icon fa-fw "></i>
                <span> @Model.DisplayName</span>
            </a>
        }
    }
    else
    {
        <a class="nav-link collapsed" href="#" data-toggle="collapse" data-target="#@collapsePages" aria-expanded="true" aria-controls="collapseTwo">
            <i class="@icon fa-fw "></i>
            <span> @Model.DisplayName</span>
        </a>
        <div id="@collapsePages" class="collapse @(isActive?" show":"")" aria-labelledby="headingUtilities" data-parent="#accordionSidebar">
            <div class="bg-white py-2 collapse-inner rounded">
                @foreach (var childMenuItem in Model.Items)
                {
                    <a class="collapse-item  @(this.Context.Request.Path == childMenuItem.Url?"active":"")" href="@(childMenuItem.Url ?? " #")">
                        <i class="@(childMenuItem.Icon ?? " ") fa-fw"></i>
                        @childMenuItem.DisplayName
                    </a>
                }
            </div>
        </div>
    }
</li>


